<template>
	<div>
		<el-row class="row">
			<h3>审核详情</h3>
			<hr />
			<el-col class="showdetail" :span="12">
				<p>
					<label>姓名:</label>
					{{agentdata.uname}}
				</p>
				<p>
					<label>手机:</label>
					{{agentdata.uphone}}
				</p>
				<p>
					<label>城市:</label>
					{{agentdata.city}}
				</p>
				<p>
					<label>意向:</label>
					{{agentdata.product}}
				</p>
				<p>
					<label>申请时间:</label>
					{{agentdata.faddtime}}
				</p>
				<p>
					<label>备注:</label>
					{{agentdata.remark}}
				</p>
				<p>
					<label>状态:</label>
					<span style="color: red;">{{agentdata.fstate}}</span>
					
				</p>
			</el-col>
			<el-col :span="12">
				
				<el-row>
					<label style="">身份证:</label><br />
					<hr />
					<a href="static/img/img.146655c9.jpg" target="_blank"><img src="../../../assets/img/img.jpg" width="100" /></a>
					
				</el-row>
				
				<el-row style="margin-top: 30px;">
					<label style="">机构证:</label><br />
					<hr />
					<a href="static/img/img.146655c9.jpg" target="_blank"><img src="../../../assets/img/img.jpg" width="100" /></a>
				</el-row>

			</el-col>
		</el-row>

		<el-row v-if="agentdata.fstate=='未审核'" class="row">
			<h3>代理审核 <span style="color: red;"> (赶紧审核)</span></h3>
			<hr />
			<el-form :model="agentdata" :rules="rules" ref="agentdata" label-width="100px"
			 class="demo-agentdata">

				<el-form-item label="代理商类别" prop="agenttype">
					<el-radio-group v-model="agentdata.agenttype">
						<el-radio label="市代"></el-radio>
						<el-radio label="省代"></el-radio>
					</el-radio-group>
				</el-form-item>

				<div v-if="agentdata.agenttype!=null">
					<el-form-item v-if="agentdata.agenttype=='市代'" label="选择省代" prop="province1">
						<el-select v-model="agentdata.province1" placeholder="选择省代">
							<el-option v-for="ones in oneagents" :label="ones.fnickname" :value="ones.id"></el-option>
						</el-select>
					</el-form-item>

					<el-form-item label="个人/机构" prop="pertype">
						<el-radio-group v-model="agentdata.pertype">
							<el-radio label="个人"></el-radio>
							<el-radio label="机构"></el-radio>
						</el-radio-group>
					</el-form-item>

					<div v-if="agentdata.pertype=='机构'">
						<el-form-item label="机构" prop="company">
							<el-input v-model="agentdata.company" value="agentdata.company"></el-input>
						</el-form-item>

						<el-form-item label="机构号" prop="companyid">
							<el-input v-model="agentdata.companyid" value="agentdata.companyid"></el-input>
						</el-form-item>
					</div>
					
					<el-form-item v-if="" label="代理商名称" prop="fnickname">
						<el-input v-model="agentdata.fnickname" value="agentdata.fnickname"></el-input>
					</el-form-item>

					<el-form-item v-if="" label="姓名" prop="uname">
						<el-input v-model="agentdata.uname" value="agentdata.uname"></el-input>
					</el-form-item>

					<el-form-item label="身份证" prop="fidcode">
						<el-input v-model="agentdata.fidcode" value="agentdata.fidcode"></el-input>
					</el-form-item>

					<el-form-item label="手机" prop="uphone">
						<el-input v-model="agentdata.uphone" value="agentdata.uphone"></el-input>
					</el-form-item>

					<el-form-item label="备注" prop="remark">
						<el-input type="textarea" v-model="agentdata.remark"></el-input>
					</el-form-item>
					
					<el-form-item label="地址" prop="faddress">
						<el-input type="textarea" v-model="agentdata.faddress"></el-input>
					</el-form-item>
					
					<el-form-item label="登录密码" prop="upass">
						<el-input type="password" v-model="agentdata.upass" value="agentdata.upass"></el-input>
					</el-form-item>

					<el-form-item>
						<el-button type="primary" @click="submitForm('agentdata')">审核通过</el-button>
					</el-form-item>
				</div>
				
				<el-form-item>
					<el-button type="primary" style="background-color: red;" @click="checkfail()">审核不通过</el-button>
				</el-form-item>


			</el-form>
		</el-row>


	</div>
</template>

<script>
	import fenxiaoapi from '../../common/fenxiaoserver.js';
	export default {
		name: 'index',
		data() {
			return {
				oneagents:[],
				agentdata: {

				},
				rules: {
					fnickname:[{
							required: true,
							message: '代理商名称',
							trigger: 'blur'
						},
						{
							min: 0,
							max: 32,
							message: '最大长度为8',
							trigger: 'blur'
						}
					],
					faddress: [{
							required: true,
							message: '联系地址不能为空',
							trigger: 'blur'
						},
						{
							min: 0,
							max: 32,
							message: '最大长度为32',
							trigger: 'blur'
						}
					],
					upass: [{
							required: true,
							message: '密码不能为空',
							trigger: 'blur'
						},
						{
							min: 8,
							max: 32,
							message: '最小长度为8',
							trigger: 'blur'
						}
					],
					province1: [{
							required: true,
							message: '请选择省代名下',
							trigger: 'blur'
						}
					],
					uphone: [{
							required: true,
							message: '请输入手机号码',
							trigger: 'blur'
						},
						{
							min: 1,
							max: 32,
							message: '长度最大32',
							trigger: 'blur'
						}
					],
					fidcode: [{
							required: true,
							message: '请输入身份证号',
							trigger: 'blur'
						},
						{
							min: 1,
							max: 32,
							message: '长度最大32',
							trigger: 'blur'
						}
					],
					companyid: [{
							required: true,
							message: '请输入机构号',
							trigger: 'blur'
						},
						{
							min: 1,
							max: 32,
							message: '长度最大32',
							trigger: 'blur'
						}
					],
					pertype: [{
							required: true,
							message: '请选择个人/机构',
							trigger: 'blur'
						},
						{
							min: 1,
							max: 10,
							message: '长度最大10',
							trigger: 'blur'
						}
					],
					uname: [{
							required: true,
							message: '请输入姓名',
							trigger: 'blur'
						},
						{
							min: 1,
							max: 10,
							message: '长度最大10',
							trigger: 'blur'
						}
					],
					company: [{
							required: true,
							message: '请输入机构',
							trigger: 'blur'
						},
						{
							min: 0,
							max: 20,
							message: '长度最大20',
							trigger: 'blur'
						}
					]
				}
			};
		},
		created() {
			console.log(this.$route.query);
		},
		components: {

		},
		computed: {

		},
		mounted() {
			this.getdata();
			this.getoneagents();
		},
		methods: {
			getoneagents(){
				var _this = this;
				fenxiaoapi.GetOneAgents(this,'*',1,100,function(d){
					console.log(d);
					if(d.code == 200){
						_this.oneagents = d.data.list;
					}
					
				},function(d){})
			},
			getdata() {
				// this.vuex_user.token /agent_checkagent_list?token=fasddf
				var _this = this;
				$.ajax({
					url: this.url + '/autoagent_details',
					data: {
						'token': this.vuex_user.token,
						'id': this.$route.query.id
					},
					success: (data) => {
						console.log(data);
						_this.agentdata = data.data;
						_this.agentdata.faddtime = _this.agentdata.faddtime.replace('T',' ')
						if(_this.agentdata.fstate == 'nopass'){
							_this.agentdata.fstate = '未审核';
						}else if(_this.agentdata.fstate == 'ispass'){
							_this.agentdata.fstate = '已审核';
						}else{
							_this.agentdata.fstate = '未通过';
						}
					},
					error() {
						this.$message.error('服务器错误！');
					}
				});
			},
			submitForm(formName) {
				var _this = this;
				this.$refs[formName].validate((valid) => {
					if (valid) {
						// alert('submit!');
						console.log(this.agentdata)
						fenxiaoapi.AutoAgentPass(this,this.agentdata.id,JSON.stringify(this.agentdata),function(msgs){
							console.log(msgs);
							_this.$message.success('审核通过！');
							_this.getdata();
						},function(msgs){
							
						});
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
			checkfail(){
				var _this = this;
				fenxiaoapi.AutoAgentNoPass(this,this.agentdata.id,function(msgs){
					_this.$message.error('审核不通过！');
					_this.getdata();
				},function(msgs){
					
				})
			}
		}
	};
</script>


<style scoped>
.showdetail p{
	padding: 15px;
}
.showdetail label{
	width: 150px;
	display:inline-block;
}
</style>
